package vault

import "gitee.com/git_public/vfaith/builtin/shape"

type PageCondition struct {
	PageNow     int `json:"pageNow"`
	PageLimit   int `json:"pageLimit"`
	TotalRecord int `json:"totalRecord"`
	TotalPages  int `json:"totalPages"`
}

func NewPageCondition(argsMap *shape.Map) *PageCondition {
	pageNow := argsMap.ValueInt("pageNow")
	pageLimit := argsMap.ValueInt("pageLimit")

	if pageNow < 1 || pageLimit < 1 {
		return &PageCondition{
			PageNow:     1,
			PageLimit:   20,
			TotalRecord: 0,
			TotalPages:  0,
		}
	} else {
		return &PageCondition{
			PageNow:     pageNow,
			PageLimit:   pageLimit,
			TotalRecord: 0,
			TotalPages:  0,
		}
	}
}

func (param *PageCondition) SetTotalNum(totalRecord int) {
	param.TotalRecord = totalRecord
	if param.PageNow > 0 && param.PageLimit > 0 {
		//param.totalPages = int((totalRecord + int64(param.pageLimit) - 1) / int64(param.pageLimit))
		param.TotalPages = (totalRecord + param.PageLimit - 1) / param.PageLimit
	}
}
